package com.unytech.wisdomcommunity.mainfragment;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.unytech.wisdomcommunity.R;
import com.unytech.wisdomcommunity.activity.ComlainRepairRecordActivity;
import com.unytech.wisdomcommunity.activity.EmptyActivity;
/**
 * Created by zed on 2016/11/2/0027.
 *
 * 11.10 16:45  这里是要实现点击圆形图片  弹出自定义对话框或者自定义的popwindows
 *              然后调用手机自带的相册或者开启手机摄像头
 *              开启手机摄像头的话,拍摄完成之后将拍摄的照片自动获取到,进行头像编辑
 */

/**
 * "我的"fragment
 */
public class MeFragment2 extends BaseFragment2 implements View.OnClickListener{
    private ImageView circleIv;
    private TextView tv_1,tv_2,tv_cel;
    private LinearLayout mComlainRepairRecord;

    private View.OnClickListener CircleIvListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), EmptyActivity.class);
            startActivity(intent);
            Toast.makeText(getActivity(),"点击了tupian",Toast.LENGTH_SHORT).show();
            //TODO 11.10 16:45  这里是要实现点击圆形图片  弹出popwindows
            //然后调用手机自带的相册或者开启手机摄像头
            //开启手机摄像头的话,拍摄完成之后将拍摄的照片自动获取到,进行头像编辑
            //PopupWindow
            //showPopupWindow();
        }
    };

    //显示popupWindow
    private void showPopupWindow() {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.popup_window_layout, null);

        PopupWindow pop=new PopupWindow(getActivity());
        pop.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        pop.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
        pop.setTouchable(true);
        pop.setFocusable(true);
        pop.setOutsideTouchable(true);
        pop.setBackgroundDrawable(new ColorDrawable(0000000000));
        pop.showAtLocation(circleIv, Gravity.BOTTOM,0,0);

        setContentViewClickListener(view);

        pop.setContentView(view);
    }

    private void setContentViewClickListener(View view) {
        tv_1 = ((TextView) view.findViewById(R.id.pop_tv_1));
        tv_2 = ((TextView) view.findViewById(R.id.pop_tv_2));
        tv_cel = ((TextView) view.findViewById(R.id.pop_tv_cel));

        tv_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(),"点击了1",Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    protected int getContentLayoutRes() {
        return R.layout.me_fragment;
    }

    @Override
    protected void initView(View childView) {
        circleIv = ((ImageView) childView.findViewById(R.id.me_fragment_cc_iv));
        circleIv.setOnClickListener(CircleIvListener);

        mComlainRepairRecord = ((LinearLayout) childView.findViewById(R.id.comlain_repair_record_ll));
        mComlainRepairRecord.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.comlain_repair_record_ll:
                startActivity(new Intent(getActivity(),ComlainRepairRecordActivity.class));//点击进入"投诉报修记录"页面
                break;
        }
    }
}